/* 
 * Copyright (C) 2015 fede
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package Entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author fede
 */
@Entity
public class Calendar implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    //association with RegisteredUser
    //owner of calendar
    //this is also the primary key of the table
    @OneToOne
    private RegisteredUser owner;

    private Boolean public_bool;

    //association with Event
    @ManyToMany
    private List<Event> event;

    /**
     * Find all calendar
     */
    public static final String FIND_ALL = "Calendar.findAll";

    /**
     * this method allow to get the owner of the current calendar
     *
     * @return registeredUser setted as owner
     */
    public RegisteredUser getOwner() {
        return owner;
    }

    /**
     * this method allow to set the owner of the current calendar
     *
     * @param owner registeredUser to set as owner
     */
    public void setOwner(RegisteredUser owner) {
        this.owner = owner;
    }

    /**
     * this method allow to get an event list for current calendar
     *
     * @return list of event of current calendar
     */
    public List<Event> getEvent() {
        return event;
    }

    /**
     * this method allow to set an event list for current calendar
     *
     * @param event a list of event to set
     */
    public void setEvent(List<Event> event) {
        this.event = event;
    }

    /**
     * this method allow to add an event for current calendar
     *
     * @param e Event to add
     */
    public void addEvent(Event e) {
        event.add(e);
    }

    /**
     * this method allow to delete an event from current calendar
     *
     * @param e Event to delete
     */
    public void deleteEvent(Event e) {
        event.remove(e);
    }

    /**
     * this method get the public or private visibility of calendar
     *
     * @return boolean value
     */
    public Boolean getPublic_bool() {
        return public_bool;
    }

    /**
     * this method set the public or private visibility to calendar
     *
     * @param public_bool public=true, private=false
     */
    public void setPublic_bool(Boolean public_bool) {
        this.public_bool = public_bool;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (owner != null ? owner.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Calendar)) {
            return false;
        }
        Calendar other = (Calendar) object;
        if ((this.owner == null && other.owner != null) || (this.owner != null && !this.owner.equals(other.owner))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Calendar[ id=" + owner + " ]";
    }

}
